Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

200
Visualizações
mongodb update fails due to _id without the "ObjectId" text

I have a script that identified two records that I need to update. My query returned the two _id values as: 62bdca65a69a2cdf17978992 and 62c06c18d694a13c4a29c078. I generated update the statements:

db.people.updateOne({_id: ObjectId('62bdca65a69a2cdf17978992')}, {$set: {dept: 22}});
db.people.updateOne({_id: ObjectId('62c06c18d694a13c4a29c078')}, {$set: {dept: 22}});

Only one got updated and examination of the data showed that one has the _id: 62bdca65a69a2cdf17978992 and the other has the _id as ObjectId('62c06c18d694a13c4a29c078').

  1. Can I somehow determine if the "ObjectId" part of the _id exists so that I can dynamically include or exclude that in my update?
  2. Can I write the update statement in a generic way so both get updated?
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda